package top.withu.gaof.freehope.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.withu.gaof.freehope.dao.UserDao;
import top.withu.gaof.freehope.model.User;
import top.withu.gaof.freehope.service.UserService;
import top.withu.gaof.freehope.utils.JWTUtil;

/**
 * @author Gaofan
 * @date 2019年4月23日 上午11:19:21
 * @describe
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Override
	public Boolean login(String userName, String pwd) {
		User user = userDao.getUser(userName, pwd);
		if (null == user) {
			return Boolean.TRUE;
		}
		return Boolean.FALSE;
	}

	@Override
	public User createUser(User user) {
		String token = JWTUtil.getToken(user);
		user.setToken(token);
		User userRes = userDao.saveAndFlush(user);
		return userRes;
	}

	@Override
	public String getStr() {
		return "GET DATA SUCCESS!";
	}


}
